//
//  BannerCollectionViewModel.swift
//  iPhone
//
//  Created by Toj on 5/24/23.
//

import UIKit

class BannerCollectionViewModel: NSObject {

   private var _sections: [UICollectionViewSectionModelProtocol] = []
    
    func requestBannerAds() {
        var sections: [UICollectionViewSectionModelProtocol] = []
        
        var section = GeneralSectionModel()
        var random: Int = 5 { didSet {
            print("-->toj: random---- :\(random)")
        } }
        random = Int(arc4random_uniform(5))+1
        var index = 1
        var movies = [UICollectionViewCellModelProtocol]()
        
        for i in 1..<200 {
            if index == random {
                if !movies.isEmpty {
                    section = GeneralSectionModel(items: movies)
                    sections.append(section)
                }
                movies = [UICollectionViewCellModelProtocol]()
                random = Int(arc4random_uniform(10)) + 1
                index = 1
                
                var banners = [UICollectionViewCellModelProtocol]()
                let bannerAdCellModel = BannerAdCellModel(BannerAdModel())
              
                banners.append(bannerAdCellModel)
                section = GeneralSectionModel(items: banners)
                sections.append(section)
                continue
                //break
            }
            index += 1
            
            let moviesCellModel = MoviesCellModel(MoviesModel(index: i))
            movies.append(moviesCellModel)
        }
        
        let moviesCellModel = MoviesCellModel(MoviesModel(index: 999))
        movies.append(moviesCellModel)
        section = GeneralSectionModel(items: movies)
        sections.append(section)
        
        _sections = sections
    }
}

extension BannerCollectionViewModel: UICollectionViewModelProtocol {
    
    var sections: [UICollectionViewSectionModelProtocol] {
        return _sections
    }
}
